<?php
include 'score_lib.php';

$a_score_log = array ( );
$a_user = array ( );
$f_note = '';

$db_query = "
            select  score, updatedate, updaterid, note
            from    user_score_log
            where   userid = '$f_userid' and data = '$f_data' and scoretype = '$f_scoretype' and type = 'HOC_LUC'
            order by updatedate desc";

$db_result = db_query($db_conn, $db_query);

while ($d_row = db_fetch($db_result)) {

    $a_score_log[]             = $d_row;
    $a_user[$d_row->updaterid] = $d_row->updaterid;
    $f_note                    = $f_note ? $f_note : $d_row->note; //First item is the lastes note.
}

$db_query  = db_get_query($a_tablecolumns_namhoa_user) . "where userid in ('" . implode("', '", $a_user) . "') ";
$db_result = db_query($db_conn, $db_query);
$a_user    = array ( );

while ($d_row = db_fetch($db_result)) {
    $a_user[$d_row->userid] = $d_row;
}
?>
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
    <h3><?= $f_username ?></h3>
</div>
<div class="modal-body">
    <input type="hidden" name="userid" value="<?= $f_userid ?>"> 
    <input type="hidden" name="data" value="<?= $f_data ?>"> 
    <input type="hidden" name="scoretype" value="<?= $f_scoretype ?>"> 
    <div class="row-fluid form-horizontal">
        <div class="control-group">
            <label class="control-label"><?= @$a_Dot_KiemTra[$f_scoretype] ?> - <?= @$a_SoLan_KiemTra[$f_data] ?></label>
            <div class="controls text-center">
                <input type="text" name="score" value="<?= $f_score ?>" placeholder="Ví Dụ: 8.75" class="text-center span12 m-wrap" />
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">Ghi Chú</label>
            <div class="controls">
                <textarea rows="3" name="note" class="span12 m-wrap"><?=$f_note?></textarea>
            </div>
        </div>
    </div>
    <?php if (!empty($a_score_log)) { ?>
        <table class="table table-hover">
            <thead>
                <tr>
                    <th>Ngày</th>
                    <th>Tên Thánh - Họ và Tên</th>
                    <th>Điểm</th>
                    <th>Ghi Chú</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($a_score_log as $o_Log) { ?>
                    <tr>
                        <td><?= namhoa_date($o_Log->updatedate, true) ?></td>
                        <td><?= $a_user[$o_Log->updaterid]->saint ?> <?= $a_user[$o_Log->updaterid]->username ?></td>
                        <td><?= $o_Log->score ?></td>
                        <td><?= $o_Log->note ?></td>
                    </tr>
                <?php } ?>
            </tbody>
        </table>
    <?php } ?>
</div>
<div class="modal-footer">
    <button type="button" data-dismiss="modal" class="btn">Thoát</button>
    <button type="button" class="btn blue btn-save">Lưu</button>
</div>